﻿var EditBrandModal = (function ($) {
    app.modals.EditBrandModal = function () {

        var _modalManager;
        var _brandService = abp.services.app.brand;
        var _$brandForm = null;


        this.init = function (modalManager) {
            _modalManager = modalManager;

            _$brandForm = _modalManager.getModal().find('form[name=BrandForm]');
            _$brandForm.validate();
        };

        this.save = function () {
            if (!_$brandForm.valid()) {
                return;
            }

            var brand = _$brandForm.serializeFormToObject();

            _modalManager.setBusy(true);
            _brandService.updateBrand(
                brand
            ).done(function () {
                abp.notify.info(app.localize('SavedSuccessfully'));
                _modalManager.close();
                abp.event.trigger('app.editBrandModalSaved');
            }).always(function () {
                _modalManager.setBusy(false);
            });
        };
    };
})(jQuery);